import React from 'react'
import {Router} from 'dva/router'
import App from './public/layout/routes/index';

export default function ({history, app}) {
  const cached = {};
  function registerModel(app, model) {
    if (!cached[model.namespace]) {
      app.model(model);
      cached[model.namespace] = 1;
    }
  };
  const routes = [
    {
      path: '/login',
      getIndexRoute(nextState, cb) {
        require.ensure([], require => {
          registerModel(app, require("./public/layout/models/login/login"));
          cb(null, {component: require('./public/layout/routes/login/Login')})
        })
      }
    },
    {
      path: '/', component: App,
      getIndexRoute(nextState, cb) {
        require.ensure([], require => {
          cb(null, {component: require('./public/layout/routes/IndexPage')})
        })
      },
      childRoutes: [
        /*//切莫删除下面两行注释,用来做标记-自动化代码生成导入-任志强*/
        /*startRoute*/
        {
          path: '/dome/:MenuId',
          name: '案例',
          getIndexRoute(nextState, cb) {
            require.ensure([], require => {
              registerModel(app, require("./models/dome/index"));
              registerModel(app, require("./models/dome/add"));
              cb(null, {component: require("./routes/dome/index")})
            })
          }
        },
        {
          path: '/dome1/:MenuId',
          name: '案例',
          getIndexRoute(nextState, cb) {
            require.ensure([], require => {
              registerModel(app, require("./models/dome/index"));
              registerModel(app, require("./models/dome/add"));
              cb(null, {component: require("./routes/dome/index")})
            })
          }
        },
        {
          path: '/dome2/:MenuId',
          name: '案例',
          getIndexRoute(nextState, cb) {
            require.ensure([], require => {
              registerModel(app, require("./models/dome/index"));
              registerModel(app, require("./models/dome/add"));
              cb(null, {component: require("./routes/dome/index")})
            })
          }
        }
        /*endRoute*/
      ]
    }
  ]
  return <Router history={history} routes={routes}/>
}
